package com.zz.common

import akka.actor.ActorSystem
import akka.stream.Materializer
import cats.effect.{Async, ContextShift, IO}
//import com.zz.dsp.aerospike.{AsClient, AsConfig, SimpleAsyncAsClient}
//import com.zz.dsp.database.DatabaseComponentF

object GlobalContext {

  def default[F[_]]()(implicit system: ActorSystem, mat: Materializer, cs: ContextShift[F], as: Async[F]): GlobalContext[F] = {
    val config = AppConfig.loadOrThrow()
    GlobalContext[F](system = system,
                     mat = mat,
                     config = config
//                     dc = DatabaseComponentF(config.database),
//                     aerospike = SimpleAsyncAsClient(AsConfig("aerospike.cluster.main"))
    ) // 这里的配置参考tracking_streaming
  }

  def defaultIO()(implicit system: ActorSystem, mat: Materializer, cs: ContextShift[IO], as: Async[IO]): GlobalContext[IO] =
    this.default[IO]()
}

final case class GlobalContext[F[_]: Async: ContextShift](
    system: ActorSystem
  , mat: Materializer
  , config: AppConfig
//  , dc: Resource[F, DatabaseComponentF[F]]
//  , aerospike: AsClient
)
